package com.shiguiwu.springmybatis.javabase.generics;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.Arrays;

/**
 * @description: 泛型
 * @author: stone
 * @date: Created by 2021/3/12 11:28
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.generics
 */
public class GenericsMethod{

    public <T1, T2 extends Integer, T3 extends GenericsOne & GenericsTwo> T3 test(T1 t1, T2 t2, T3 t3, String s) {
        return t3;
    }

    public static void main(String[] args) {
        Method[] methods = GenericsMethod.class.getDeclaredMethods();

        Method test = null;
        for (Method method : methods) {
            if ("test".equalsIgnoreCase(method.getName())) {
                test = method;
                break;
            }
        }

        if (test == null) {
            return;
        }

        System.out.println("方法返回值的参数类型信息====================================");
        Type genericReturnType = test.getGenericReturnType();
        if (genericReturnType instanceof TypeVariable) {
            TypeVariable typeVariable = (TypeVariable) genericReturnType;
            System.out.println("变量名称：" + typeVariable.getName());
            System.out.println("这个变量在哪里声明：" + typeVariable.getGenericDeclaration());
            Type[] bounds = typeVariable.getBounds();
            System.out.println("上边界。。。。。。。。。。。。。。。。。");
            System.out.println(Arrays.toString(bounds));
        }

        System.out.println("方法上的参数类型列表============================================");

        TypeVariable<Method>[] genericParameterTypes = test.getTypeParameters();
        for (TypeVariable<Method> typeVariable : genericParameterTypes) {
            System.out.println("变量名称：" + typeVariable.getName());
            System.out.println("这个变量在哪里声明：" + typeVariable.getGenericDeclaration());
            Type[] bounds = typeVariable.getBounds();
            System.out.println("上边界。。。。。。。。。。。。。。。。。");
            System.out.println(Arrays.toString(bounds));

        }

    }
}
